﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FlashGameSite.Manager
{
    public enum ActivityType
    {
        NewMember = 0,
        GamePlaying,
        GameComment,
        GameLike,
        Custom
    }

    public class Common
    {
        public static void AddMemberActivity(string username, long userId, string customText, ActivityType activityType)
        {
            string activityText = "";
            string actType = "";
            switch (activityType)
            {
                case ActivityType.NewMember:
                    actType = "NEW";
                    activityText = string.Format("<span>New member joined. Please welcome </span><a href=\"UserInfo.aspx?uid={0}\">{1}</a>", userId, username);
                    break;
                case ActivityType.Custom:
                    actType = "CUSTOM";
                    activityText = string.Format("<a href=\"UserInfo.aspx?uid={0}\">{1}</a> says: <strong>{2}</strong>", userId, username, customText);
                    break;
                default:
                    break;
            }

            if (!string.IsNullOrEmpty(activityText))
            {
                using (FlashGamesDataContext dataContext = new FlashGamesDataContext())
                {
                    dataContext.AddMemberActivity(activityText, null, null, username, userId, actType);
                }
            }
        }

        public static void AddMemberActivity(string username, long userId, string gameTitle, int gameId, string imageUrl, ActivityType activityType)
        {
            string activityText = "";
            string actType = "";
            switch (activityType)
            {
                case ActivityType.GamePlaying:
                    actType = "PLAY";
                    activityText = string.Format("<a href=\"UserInfo?uid={0}\">{1}</a> started playing <a href=\"PlayGame.aspx?gameid={2}\">{3}</a> &nbsp;&nbsp; <img src=\"gameimage/{4}\" />",
                                                userId, username, gameId, gameTitle, imageUrl);
                    break;
                case ActivityType.GameComment:
                    actType = "COMMENT";
                    activityText = string.Format("<a href=\"UserInfo?uid={0}\">{1}</a> commented on game <a href=\"PlayGame.aspx?gameid={2}\">{3}</a> &nbsp;&nbsp; <img src=\"gameimage/{4}\" />",
                                                userId, username, gameId, gameTitle, imageUrl);
                    break;
                case ActivityType.GameLike:
                    actType = "LIKE";
                    activityText = string.Format("<a href=\"UserInfo?uid={0}\">{1}</a> liked a game <a href=\"PlayGame.aspx?gameid={2}\">{3}</a> &nbsp;&nbsp; <img src=\"gameimage/{4}\" />",
                                                userId, username, gameId, gameTitle, imageUrl);
                    break;
                default:
                    break;
            }

            if (!string.IsNullOrEmpty(activityText))
            {
                using (FlashGamesDataContext dataContext = new FlashGamesDataContext())
                {
                    dataContext.AddMemberActivity(activityText, gameId, imageUrl, username, userId, actType);
                }
            }
        }

        public static void SendMail(string emailId, string subject, string message)
        {

        }
    }
}